#include<bits/stdc++.h>
using namespace std;
inline bool valid(vector<int> &p){
  for(int i=0;i<p.size()-2;i++){
    int mn=p[i+1],mx=p[i+1];
    for(int j=i+2;j<p.size();j++){
      int l=min(p[i],p[j]),r=max(p[i],p[j]);
      if(mx>r&&mn<l)return false;
      mx=max(mx,p[j]),mn=min(mn,p[j]);
    }
  }
  return true;
}
inline int dis(vector<int> &a,vector<int> &b){
  int c=0;
  for(int i=0;i<a.size();i++)
    c+=a[i]!=b[i];
  return c;
}
int main(){
  freopen("build.in","r",stdin);
  freopen("build.out","w",stdout);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  vector<int> h(n);
  for(auto &i:h)cin>>i,i--;
  int c=n;
  if(n<=7){
    vector<int> p(n);
    iota(p.begin(),p.end(),0);
    do{
      if(valid(p))c=min(c,dis(p,h));
    }while(next_permutation(p.begin(),p.end()));
  }
  cout<<c<<endl;
  return 0;
}